#if !USE_CONSOLE

#include "src/interface/translateDialog.h"

TranslateDialog::TranslateDialog(QList<TreeItem *> _list, QWidget *_parent) : QDialog(_parent), list(_list){
    setWindowTitle(QString::fromUtf8("Translação"));
    translateX = translateY = translateZ = 0;

    QLabel *translateXLabel = new QLabel(tr("X:"));

    QDoubleSpinBox *translateXDoubleSpinBox = new QDoubleSpinBox();
    translateXDoubleSpinBox->setRange(-50.0, 50.0);
    translateXDoubleSpinBox->setSingleStep(1.0);
    translateXDoubleSpinBox->setValue(translateX);
    connect(translateXDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(changeTranslateX(double)));


    QLabel *translateYLabel = new QLabel(tr("Y:"));

    QDoubleSpinBox *translateYDoubleSpinBox = new QDoubleSpinBox();
    translateYDoubleSpinBox->setRange(-50.0, 50.0);
    translateYDoubleSpinBox->setSingleStep(1.0);
    translateYDoubleSpinBox->setValue(translateY);
    connect(translateYDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(changeTranslateY(double)));


    QLabel *translateZLabel = new QLabel(tr("Z:"));

    QDoubleSpinBox *translateZDoubleSpinBox = new QDoubleSpinBox();
    translateZDoubleSpinBox->setRange(-50.0, 50.0);
    translateZDoubleSpinBox->setSingleStep(1.0);
    translateZDoubleSpinBox->setValue(translateZ);
    connect(translateZDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(changeTranslateZ(double)));


    QHBoxLayout *translateLayout = new QHBoxLayout;
    translateLayout->addWidget(translateXLabel);
    translateLayout->addWidget(translateXDoubleSpinBox);
    translateLayout->addStretch(1);
    translateLayout->addWidget(translateYLabel);
    translateLayout->addWidget(translateYDoubleSpinBox);
    translateLayout->addStretch(1);
    translateLayout->addWidget(translateZLabel);
    translateLayout->addWidget(translateZDoubleSpinBox);
    translateLayout->addStretch(1);

    QGroupBox *translateGroupBox = new QGroupBox(QString::fromUtf8("Vetor translação"));
    translateGroupBox->setLayout(translateLayout);


    QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
    connect(buttonBox, SIGNAL(accepted()), this, SLOT(acceptAndCreate()));
    connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
    buttonBox->setLocale(QLocale(QLocale::Portuguese, QLocale::Brazil));

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(translateGroupBox);
    mainLayout->addWidget(buttonBox);
    mainLayout->addStretch(1);

    setLayout(mainLayout);

}

TranslateDialog::~TranslateDialog(){
}

void TranslateDialog::acceptAndCreate(){
    Vector3D translateVector(translateX, translateY, translateZ);
    for(int i = 0; i < list.size(); i++){
        QTreeWidgetItem *item = list.at(i);
//        item->setSelected(false);
        ((ObjectTreeItem *)item)->getObject()->translate(translateVector);
    }

    accept();
    done();
}

void TranslateDialog::changeTranslateX(double _x){
    translateX = _x;
}

void TranslateDialog::changeTranslateY(double _y){
    translateY = _y;
}

void TranslateDialog::changeTranslateZ(double _z){
    translateZ = _z;
}
#endif //!USE_CONSOLE
